﻿<%@ WebHandler Language="VB" Class="RequestTicketEvent" %>

Imports System
Imports System.Web
Imports System.Collections.Generic
Imports System.Linq

Public Class RequestTicketEvent : Implements IHttpHandler
   
    Dim SearchBy As String
   
    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
        
        SearchBy = context.Request("reftype")
       
        getTable(context)
    End Sub
    Public Sub getTable(ByVal cont As HttpContext)
        
        Dim SQLDB As New OneCall.DataModel.OneCDataEntities
        Dim RequestList As New List(Of OneCall.DataModel.Request)
        
        If SearchBy = "all" Then
            RequestList = (From p In SQLDB.Requests Select p).ToList()
        ElseIf SearchBy = "open" Then
            RequestList = (From p In SQLDB.Requests Where p.Request_Status = 0 Select p).ToList()
        ElseIf SearchBy = "close" Then
            RequestList = (From p In SQLDB.Requests Where p.Request_Status = 1 Select p).ToList()
        End If
                
        Dim ret As String = "<?xml version='1.0' encoding=""utf-8""?>"
        ret = ret & "<rows>"
        ret = ret & "<page>1</page>"
        ret = ret & "<total>1</total>"
        ret = ret & "<records>" & RequestList.Count & "</records>"
        
        For Each requests As OneCall.DataModel.Request In RequestList
            
            ret = ret & "<row>"
            ret = ret & "<cell>" & requests.Request_ID & "</cell>"
            ret = ret & "<cell><![CDATA[ " & requests.Request_Reference & "]]></cell>"
            ret = ret & "<cell><![CDATA[ " & requests.Request_AssignedTo & "]]></cell>"
            ret = ret & "<cell><![CDATA[ " & requests.Request_Type  & "]]></cell>"
            ret = ret & "<cell><![CDATA[ " & requests.Request_Subject & "]]></cell>"
            'ret = ret & "<cell><![CDATA[ " & requests.Request_Description & "]]></cell>"
            ' ret = ret & "<cell><![CDATA[ " & requests.Request_CustomerID & "]]></cell>"
            ' ret = ret & "<cell><![CDATA[ " & requests.Request_Status & "]]></cell>"
            ret = ret & "<cell><![CDATA[ " & requests.Request_Date & "]]></cell>"
            ret = ret & "<cell><![CDATA[ " & requests.Request_FirstName & "]]></cell>"
            'ret = ret & "<cell><![CDATA[ " & requests.Request_LastName & "]]></cell>"
            ' ret = ret & "<cell><![CDATA[ " & requests.Request_EmailID & "]]></cell>"
            ret = ret & "<cell><![CDATA[ " & requests.Request_Mobile & "]]></cell>"
            'ret = ret & "<cell><![CDATA[ " & requests.Request_Address & "]]></cell>"
            'ret = ret & "<cell><![CDATA[ " & requests.Request_City & "]]></cell>"
            'ret = ret & "<cell><![CDATA[ " & requests.Request_State & "]]></cell>"
            'ret = ret & "<cell><![CDATA[ " & requests.Request_Country & "]]></cell>"
            'ret = ret & "<cell><![CDATA[ " & requests.Request_Pin & "]]></cell>"
            'ret = ret & "<cell><![CDATA[ " & requests.Request_CustomerActStatus & "]]></cell>"
            
            ret = ret & "</row>"
            
            
            
        Next
        
        SQLDB.Dispose()
        RequestList = Nothing
               
        ret = ret & "</rows>"
        cont.Response.ContentType = "text/xml"
        cont.Response.Write(ret)
        
    End Sub
    Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class